package org.dreamwork.jasmine2.web.controls.chart.settings;

import org.dreamwork.jasmine2.util.StringConverter;

/**
 * Created by IntelliJ IDEA.
 * User: seth
 * Date: 2010-5-12
 * Time: 10:23:52
 */
public class ColumnChartSetting extends ChartSetting {
    private ChartSettingAttribute alpha = new ChartSettingAttribute ("alpha", "90");

    public ColumnChartSetting () {
        this ("xml");
    }

    public ColumnChartSetting (String dataType) {
        super (dataType);
        addSection ("column").addAttribute (alpha)
                .addAttribute ("spacing", "0")
                .addAttribute ("width", "75")
                .addAttribute (new ChartSettingAttribute ("balloon_text", "{value}", true))
                .addAttribute ("hover_brightness", "30");
        addSection ("balloon").addAttribute ("alpha", "80")
                .addAttribute ("corner_radius", "5")
                .addAttribute ("border_width", "1")
                .addAttribute ("border_color", "#000000");
        addSection ("plot_area").addSection ("margins").addAttribute ("top", "80");
        legendFormat.setValue ("{value}");
    }

    public void setType (String type) {
        if ("bar".equalsIgnoreCase (type))
            addAttribute ("type", "bar");
    }

    public void setFrequency (int frequency) {
        if (frequency != 1)
            setElementAttribute ("values.category", "frequency", String.valueOf (frequency));
    }

    public void setRotate (int rotate) {
        if (rotate != 0)
            setElementAttribute ("values.category", "rotate", String.valueOf (rotate));
    }

    public void setUnit (String unit) {
        if (!StringConverter.isEmpty (unit))
            setElementAttribute ("values.value", "unit", unit);
    }

    public void setDepth (int depth) {
        if (depth != 0)
            addAttribute ("depth", String.valueOf (depth));
    }

    public void setAlpha (int alpha) {
        if (alpha > 0 && alpha < 100)
            this.alpha.setValue (String.valueOf (alpha));
    }
}